<?php

namespace Admin\Form\Product;

use Zend\Form\Form;

class FormAddCategory extends Form {

    public function __construct($objModel) {

        parent::__construct();

        $this->setAttribute('name', 'frmAddCategory');

        $this->setAttribute('method', 'post');

        //category name
        $this->add(array(
            'name' => 'category_name',
            'type' => 'text',
            'attributes' => array(
                'class' => 'form-control',
                'maxlength' => 100
            ),
            'options' => array(
                'label' => 'Tên danh mục',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //cagetory image
        $this->add(array(
            'name' => 'category_image',
            'type' => 'file',
            'options' => array(
                'label' => 'Hình ảnh',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //category parent
        $this->add(array(
            'name' => 'category_parent',
            'type' => 'select',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'label' => 'Danh mục cha',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                ),
                'empty_option' => 'Danh mục cha',
                'value_options' => $objModel->getCategoryOptions(),
                'disable_inarray_validator' => true
            )
        ));

        $this->add(array(
            'name' => 'relation_maker_id',
            'type' => 'multi_checkbox',
            'options' => array(
                'label' => 'Hãng sản xuất',
                'label_attributes' => array(
                    'class' => 'checkbox-inline'
                ),
                'disable_inarray_validator' => true,
                'value_options' => $objModel->getMakerOption(),
            )
        ));

        //category meta title
        $this->add(array(
            'name' => 'category_meta_title',
            'type' => 'text',
            'attributes' => array(
                'class' => 'form-control',
                'maxlength' => 200
            ),
            'options' => array(
                'label' => 'Meta title',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //category meta keyword
        $this->add(array(
            'name' => 'category_meta_keyword',
            'type' => 'text',
            'attributes' => array(
                'class' => 'form-control',
                'maxlength' => 200
            ),
            'options' => array(
                'label' => 'Meta keyword',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //category meta keyword
        $this->add(array(
            'name' => 'category_meta_description',
            'type' => 'textarea',
            'attributes' => array(
                'class' => 'form-control',
                'maxlength' => 255
            ),
            'options' => array(
                'label' => 'Meta description',
                'label_attributes' => array(
                    'class' => 'col-sm-2 control-label'
                )
            )
        ));

        //for input hidden action type
        $this->add(array(
            'name' => 'action_type',
            'type' => 'hidden',
            'attributes' => array(
                'value' => 'add'
            )
        ));

        //for input hidden category id
        $this->add(array(
            'name' => 'category_id',
            'type' => 'hidden'
        ));

        //for category submit
        $this->add(array(
            'name' => 'category_submit',
            'type' => 'submit',
            'attributes' => array(
                'value' => 'Thêm',
                'class' => 'btn btn-default'
            )
        ));
    }

//    public function populateValues($data) {
//        
//        foreach ($data as $key => $row) {
//            
//                $data[$key] = new \ArrayObject($row, \ArrayObject::ARRAY_AS_PROPS);
//            
//        }
//
//        return $data;
//    }

}
